package com.site.springboot.core.controller.admin;

import com.site.springboot.core.entity.News;
import com.site.springboot.core.service.NewsService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Project:springboot-project-news-publish-system
 * ClassName:DetailsController
 * Package:com.site.springboot.core.controller.admin
 * User:CWQ
 * Description:
 *
 * @Author 合肥-陈万琼
 * @Create 2024/5/30 9:22
 * @Version 1.0
 */
@Controller
@RequestMapping("/admin")
public class DetailsController {
    @Resource
    private NewsService newsService;


    @GetMapping("/news/detail/{newsId}")
    public String detail(HttpServletRequest request, @PathVariable("newsId") Long newsId) {
        request.setAttribute("path", "edit");
        News newsDetail = newsService.queryNewsById(newsId);
        if (newsDetail == null) {
            return "error/error_400";
        }
        request.setAttribute("newsDetail", newsDetail);
        request.setAttribute("pageName","详情");
        return "index/detail";
    }

}
